<?php
/**
 * CreateTime: 2023/12/7 17:38
 * User:LinQ
 */

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Symfony\Component\HttpFoundation\Response;

class SwitchConfigMiddleware
{
    public function handle(Request $request, Closure $next): Response
    {
        $lang = request()->header('lang');
        if(!$lang){
            $lang = $request->only('lang');
        }
        if($lang){
            App::setLocale($lang);
        }
        return $next($request);
    }
}